package zhihuilan.controlle.wechatMini;

import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.HtmlUtils;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.RedisKeyEnum;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.common.enums.StaticDataEnum;
import zhihuilan.common.utils.*;
import zhihuilan.config.StaticFiledConfig;
import zhihuilan.config.WxMiniConfig;
import zhihuilan.controlle.BasicController;
import zhihuilan.dto.*;
import zhihuilan.entity.*;
import zhihuilan.entity.tools.ToolsLocation;
import zhihuilan.entity.tools.baidu.BaiduAddressComponent;
import zhihuilan.entity.tools.baidu.BaiduReverseGeocoding;
import zhihuilan.params.BaseDeleteParam;
import zhihuilan.params.BaseParams;
import zhihuilan.params.BaseSaveParams;
import zhihuilan.params.StaticParam;
import zhihuilan.params.query.*;
import zhihuilan.params.save.*;
import zhihuilan.service.*;
import zhihuilan.service.impl.MyShopServiceImpl;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 小程序端API </p>
 * 接口说明：</p>
 *
 * @Module 小程序端，获取当前登陆用户信息接口模块；
 * @Author chenk
 * @Version 1.0.1 (2025-02-24)
 */
@Slf4j
@RestController
@RequestMapping("/app/Member")
public class MyMemberController extends BasicController {

    @Resource
    private MyShopService myShopService;


    @Resource
    private StaticFiledConfig myStaffConfig;

    @Resource
    private MyConfigService myConfigService;

    @Resource
    private MyLabelService myLabelService;

    @Resource
    private MyStaffShopService myStaffShopService;

    @Resource
    private MyStaffShopGoodsService myStaffShopGoodsService;

    @Resource
    private MyCategoryStaffService myCategoryStaffService;

    @Resource
    private MyStaffSearchService myStaffSearchService;

    @Resource
    private MyCategoryShopService myCategoryShopService;

    @Resource
    private MyFactoryFavService myFactoryFavService;

    @Resource
    private MyPunishmentService myPunishmentService;

    @Resource
    private MyShopMemberService myShopMemberService;

    @Resource
    private MyOrderService myOrderService;

    @Resource
    private MyOrderDetailService myOrderDetailService;

    @Resource
    private MyCircleService myCircleService;

    @Resource
    private MyCircleCollectionService myCircleCollectionService;

    @Resource
    private MyCircleThumbupService myCircleThumbupService;

    @Resource
    private MyFactoryProductService myFactoryProductService;

    @Resource
    private MyCartService myCartService;

//    /**
//     * 根据前端传入的guid，获取当前登陆用户信息；
//     *
//     * @param queryParam 登附近店铺基础参数【RegisterQueryParam】标准查询参数类；
//     * @return 标准响应体封装返回登陆用户信息；
//     * @ApiNote
//     * @Author chenk
//     * @Version 1.0.1
//     */
//    @PostMapping("/index")
//    public WxMiniResponse memberIndex(@RequestBody RegisterQueryParam queryParam) {
//        if (!this.isCheckLogin(queryParam.getGuid())) {
//            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
//        }
//        MyStaffDto myStaffDto = new MyStaffDto();
//        BeanUtils.copyProperties(currentStaff, myStaffDto);
//        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
//        MyShopDto myShopDto = new MyShopDto();
//        if (!ObjectUtils.isEmpty(shop)) {
//            BeanUtils.copyProperties(shop, myShopDto);
//        }
//        Map<String, Object> map = new HashMap<>();
//        map.put("shopurl", myStaffConfig.getShopUrl());
//        map.put("factoryurl", myStaffConfig.getFactoryUrl());
//        map.put("shop", myShopDto);
//        map.put("factory", null);
//        map.put("telephone", "");
//        map.put("member", myStaffDto);
//        MyConfig myConfig = myConfigService.selectByName("isvideoplay");
//        if (!ObjectUtils.isEmpty(myConfig)) {
//            map.put("setting", myConfig.getValue());
//        } else {
//            map.put("setting", "false");
//        }
//        MyLabel myLabel = myLabelService.selectByName("kefutel");
//        if (!ObjectUtils.isEmpty(myLabel)) {
//            map.put("telephone", myLabel.getInfo());
//        } else {
//            map.put("telephone", "");
//        }
//        return WxMiniResponse.ok(map);
//    }

    /**
     * 获取附近店铺列表；
     *
     * @param queryParam 附近店铺基础参数【MyStaffShopQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffShopList")
    public WxMiniResponse getStaffShopList(@RequestBody MyStaffShopQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(),ResultEnum.UNLOGIN.getValue());
        }
        WxMiniPageDto<MyStaffShopDto> resultList = myStaffShopService.selectPageAndGoodsList(queryParam);
        return WxMiniResponse.ok(resultList);
    }

    /**
     * 获取我的附近店铺信息；
     *
     * @param queryParam 附近店铺基础参数【MyStaffShopQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffShopInfoByStaff")
    public WxMiniResponse getStaffShopInfoByStaff(@RequestBody MyStaffShopQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
            return WxMiniResponse.ok(null);
        }
        queryParam.setStaffId(currentStaff.getId());
        List<MyStaffShopDto> resultList = myStaffShopService.selectList(queryParam);
        if (!ObjectUtils.isEmpty(resultList) && resultList.size() > 0)
            return WxMiniResponse.ok(resultList);
        else {
            return WxMiniResponse.ok(null);
        }
    }

    /**
     * 获获取附近店铺详情；
     *
     * @param queryParam 附近店铺基础参数【MyStaffShopQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffShopInfo")
    public WxMiniResponse getStaffShopInfo(@RequestBody MyStaffShopQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.ok(null);
        }
        MyStaffShopDto result = myStaffShopService.selectById(queryParam);
        if (ObjectUtils.isEmpty(result)) {
            return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "信息不存在或已被删除", "信息不存在或已被删除");
        }
        return WxMiniResponse.ok(result);
    }

    /**
     * 验证附近店铺或者商品是否可以正常浏览；
     *
     * @param queryParam 附近店铺或商品验证参数【StoreVerifyQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getVerifyShopGoodsById")
    public WxMiniResponse getVerifyShopGoodsById(@RequestBody StoreVerifyQueryParam queryParam) {

        if (ObjectUtils.isEmpty(queryParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请至少传入一个参数");
        }
        if (ObjectUtils.isEmpty(queryParam.getShopId()) && ObjectUtils.isEmpty(queryParam.getGoodsId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请至少传入一个参数");
        }
        if (!ObjectUtils.isEmpty(queryParam.getShopId())) {
            MyStaffShop shop = myStaffShopService.selectById(queryParam.getShopId());
            if (ObjectUtils.isEmpty(shop)) {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "店铺不存在或已退店", "店铺不存在或已退店");
            }
            if (!ObjectUtils.isEmpty(queryParam.getGoodsId())) {
                MyStaffShopGoods goods = myStaffShopGoodsService.selectById(queryParam.getGoodsId());
                if (ObjectUtils.isEmpty(goods)) {
                    return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商品不存在或已删除", "商品不存在或已删除");
                } else {
                    return WxMiniResponse.ok();
                }
            } else {
                return WxMiniResponse.ok();
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数无效");
    }

    /**
     * 查询附近店铺商品分类列表
     *
     * @param queryParam 附近店铺商品分类查询参数【MyCategoryStaffQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffCategoryList")
    public WxMiniResponse getStaffCategoryList(@RequestBody MyCategoryStaffQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数错误");
        }
        if (!ObjectUtils.isEmpty(queryParam.getStaffId()) && queryParam.getStaffId() > 0) {
            queryParam.setPid(0);
        } else {
            if (ObjectUtils.isEmpty(queryParam.getShopId())) {
                queryParam.setPid(queryParam.getShopId());
            }
        }
        WxMiniPageDto<MyCategoryStaffDto> result = myCategoryStaffService.selectPageList(queryParam);
        return WxMiniResponse.ok(result);
    }

    /**
     * 查询附近店铺商品列表
     *
     * @param queryParam 附近店铺商品列表查询参数【MyStaffShopGoodsQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffShopGoodsList")
    public WxMiniResponse getStaffShopGoodsList(@RequestBody MyStaffShopGoodsQueryParam queryParam) {
//        if (!this.isCheckLogin(queryParam.getGuid())) {
//            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
//        }
        if (ObjectUtils.isEmpty(queryParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数错误");
        }
        if (!ObjectUtils.isEmpty(queryParam.getType())) {
            MyCategoryStaff myCategoryStaff = myCategoryStaffService.selectById(queryParam.getType());
            if (ObjectUtils.isEmpty(myCategoryStaff)) {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商品分类已下架");
            }
        }
        WxMiniPageDto<MyStaffShopGoodsDto> result = myStaffShopGoodsService.selectPageList(queryParam);
        return WxMiniResponse.ok(result);
    }

    /**
     * 获取附近店铺商品详情
     *
     * @param queryParam 附近店铺商品详情查询参数【MyStaffShopGoodsQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getStaffShopGoodsInfo")
    public WxMiniResponse getStaffShopGoodsInfo(@RequestBody MyStaffShopGoodsQueryParam queryParam) {
//        if (!this.isCheckLogin(queryParam.getGuid())) {
//            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
//        }
        MyStaffShopGoods selectResult = myStaffShopGoodsService.selectById(queryParam.getId());
        if (ObjectUtils.isEmpty(selectResult)) {
            return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商品已下架", "商品已下架");
        }
        MyStaffShopGoodsDto myStaffShopGoodsDto = new MyStaffShopGoodsDto();
        BeanUtils.copyProperties(selectResult, myStaffShopGoodsDto);
        return WxMiniResponse.ok(myStaffShopGoodsDto);
    }

    /**
     * 新增或更新附近店铺分类
     *
     * @param saveParam 附近店铺商品详情查询参数【MyStaffShopGoodsQueryParam】标准查询参数类；
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setStaffCategory")
    public WxMiniResponse setStaffCategory(@RequestBody MyCategoryStaffSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：数据为空!");
        }
        if (ObjectUtils.isEmpty(saveParam.getShopId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空【shopId】");
        }
        if (ObjectUtils.isEmpty(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空【name】");
        }
        if (ToolsUtils.containsEmoji(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品分类名称不能包含表情");
        }
        if (saveParam.getName().length() > 6 || saveParam.getName().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "商品分类名称应在1~6个字之间");
        }

        MyStaffShop shop = myStaffShopService.selectById(saveParam.getShopId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "店铺未创建或已退店");
        }
        if (ObjectUtils.isEmpty(saveParam.getId())) {
            // 如果id不存在，则新增；
            if (ObjectUtils.isEmpty(saveParam.getSort())) {
                saveParam.setSort(0);
            }
            saveParam.setStaffId(currentStaff.getId());
            saveParam.setPid(saveParam.getShopId());
            saveParam.setStatus(1);

            MyCategoryStaff entity = new MyCategoryStaff();
            BeanUtils.copyProperties(saveParam, entity);
            entity.setCreateTime(new Date().getTime() / 1000);
            entity.setCreateUser(currentStaff.getId() + "");
            entity = this.myCategoryStaffService.addEntity(entity);
            return WxMiniResponse.ok("添加成功");
        } else {
            // 如果id存在，则更新；
            if (ObjectUtils.isEmpty(saveParam.getSort())) {
                saveParam.setSort(0);
            }
            saveParam.setStaffId(currentStaff.getId());
            saveParam.setPid(saveParam.getShopId());
            MyCategoryStaff entity = new MyCategoryStaff();
            BeanUtils.copyProperties(saveParam, entity);
            entity.setUpdateTime(new Date().getTime() / 1000);
            entity.setUpdateUser(currentStaff.getId() + "");
            entity = this.myCategoryStaffService.updateEntity(entity);
            return WxMiniResponse.ok("更新成功");
        }
    }

    /**
     * 删除附近店铺商品分类
     *
     * @param deleteParam 封装的删除实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delStaffGoodsCategory")
    public WxMiniResponse delStaffGoodsCategory(@RequestBody BaseDeleteParam deleteParam) {
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(deleteParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }
        MyCategoryStaff selectResult = myCategoryStaffService.selectById(deleteParam.getId());
        if (ObjectUtils.isEmpty(selectResult)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：该分类不存在");
        }
        MyStaffShopGoodsQueryParam queryParam = new MyStaffShopGoodsQueryParam();
        queryParam.setType(deleteParam.getId());
        queryParam.setStaffId(currentStaff.getId());
        Long couont = myStaffShopGoodsService.selectCount(queryParam);
        if (couont > 0) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "该分类下存在商品，不能删除该分类！");
        }
        return WxMiniResponse.ok(myCategoryStaffService.deletetById(deleteParam.getId()));
    }

    @Resource
    private StaticFiledConfig myStaticConfig;

    /**
     * 附近店铺 编辑或新增商品；
     *
     * @param saveParam 封装的保存实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setStaffShopGoodsInfo")
    public WxMiniResponse setStaffShopGoodsInfo(@RequestBody MyStaffShopGoodsSaveParam saveParam) throws Exception {
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(saveParam.getShopid())) {
            saveParam.setShopid(0);
        }
        if (ObjectUtils.isEmpty(saveParam.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：附近店铺标识为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getType())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品分类不能为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品名称不能为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getImage()) && ObjectUtils.isEmpty(saveParam.getVideo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请上传至少一个商品图片或视频！");
        }
        if (ToolsUtils.containsEmoji(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品名称不能包含表情");
        }
        if (saveParam.getName().length() > 50 || saveParam.getName().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "商品名称应在1~50个字之间");
        }
        if (!ObjectUtils.isEmpty(saveParam.getRemark())) {
            if (saveParam.getRemark().length() > 500) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "商品说明不能超过500个字符");
            }
            if (ToolsUtils.containsEmoji(saveParam.getRemark())) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品说明不能包含表情");
            }
        }

        MyStaffShopGoods goods = new MyStaffShopGoods();
        BeanUtils.copyProperties(saveParam, goods);
        goods.setStaffId(currentStaff.getId());
        goods.setStatus(1);
        MySearchDto mySearch = new MySearchDto();
        if (saveParam.getShopid().equals(0)) {
            if (!ObjectUtils.isEmpty(currentStaff.getStype()) && !currentStaff.getStype().equals(1)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺不存在或已退店！");
            }
            mySearch.setDistrictid(currentStaff.getDistrictid());
            mySearch.setLat(currentStaff.getLat());
            mySearch.setLng(currentStaff.getLng());
            mySearch.setFid(0);
        } else {
            MyStaffShop shop = myStaffShopService.selectById(goods.getShopid());
            if (ObjectUtils.isEmpty(shop)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺不存在或已退店！");
            }
            mySearch.setDistrictid(shop.getDistrictid());
            mySearch.setLat(shop.getLat());
            mySearch.setLng(shop.getLng());
            mySearch.setFid(shop.getId());
        }
        MyCategoryStaff categoryStaff = myCategoryStaffService.selectById(saveParam.getType());
        if (ObjectUtils.isEmpty(categoryStaff)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品对应的该分类不存在或已被删除！");
        }
        if (ObjectUtils.isEmpty(goods.getId())) {
            goods.setCreateTime(new Date().getTime() / 1000);
            goods.setCreateUser(currentStaff.getId() + "");
            goods = myStaffShopGoodsService.addEntity(goods);
            AliPushSearchDoc aliPushSearchDoc = new AliPushSearchDoc();
            mySearch.setStaffId(goods.getStaffId());
            mySearch.setPid(goods.getId());
            mySearch.setName(goods.getName());
            mySearch.setContent(goods.getRemark());
            mySearch.setImg(goods.getImage());
            aliPushSearchDoc.addGoods(mySearch);
        } else {
            goods.setUpdateTime(new Date().getTime() / 1000);
            goods.setUpdateUser(currentStaff.getId() + "");
            goods = myStaffShopGoodsService.updateEntity(goods);
        }
        if (ObjectUtils.isEmpty(goods)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
        return WxMiniResponse.ok(goods);
    }

    /**
     * 附近店铺 更新附近店铺商品排序；
     *
     * @param saveParam 封装的更新实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setStaffShopGoodsSort")
    public WxMiniResponse setStaffShopGoodsSort(@RequestBody MyStaffShopGoodsSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(saveParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：附近店铺商品标识为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getSort())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：附近店铺商品排序序号为空！");
        }
        MyStaffShopGoods goods = myStaffShopGoodsService.selectById(saveParam.getId());
        if (ObjectUtils.isEmpty(goods)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：该商品不存在或已删除！");
        }
        Boolean result = myStaffShopGoodsService.updateSort(saveParam.getId(), saveParam.getSort());
        if (result) {
            return WxMiniResponse.ok(true);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "false");
        }
    }

    /**
     * 附近店铺 删除商品；
     *
     * @param deleteParam 封装的删除实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delStaffShopGoods")
    public WxMiniResponse delStaffShopGoods(@RequestBody BaseDeleteParam deleteParam) {
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(deleteParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }
        MyStaffShopGoods goods = myStaffShopGoodsService.selectById(deleteParam.getId());
        if (ObjectUtils.isEmpty(goods)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：该商品不存在或已被删除");
        }
        return WxMiniResponse.ok(myStaffShopGoodsService.deleteById(deleteParam.getId()));
    }


    /**
     * 附近店铺 新增或编辑附近店铺
     *
     * @param saveParam 封装的保存实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setStaffShopInfo")
    public WxMiniResponse setStaffShopInfo(@RequestBody MyStaffShopSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(saveParam.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺名称不能为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getLogo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请上传门头logo！");
        }
        if (ObjectUtils.isEmpty(saveParam.getType())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择行业分类！");
        }
        if (ObjectUtils.isEmpty(saveParam.getIntro())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入经营范围！");
        }
        if (ObjectUtils.isEmpty(saveParam.getTelephone())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入联系电话！");
        }
        if (ObjectUtils.isEmpty(saveParam.getContact())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入联系人！");
        }
        if (ObjectUtils.isEmpty(saveParam.getLat()) || ObjectUtils.isEmpty(saveParam.getLng())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择店铺地址！");
        }
        if (ObjectUtils.isEmpty(saveParam.getAddress2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入门牌号！");
        }

        if (saveParam.getTitle().length() > 20 || saveParam.getTitle().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "店铺名称应在1~20个字之间");
        }
        if (saveParam.getIntro().length() > 80 || saveParam.getIntro().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "经营范围应在1~80个字之间");
        }
        if (saveParam.getContact().length() > 10 || saveParam.getContact().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "联系人应在1~10个字之间");
        }
        if (saveParam.getAddress2().length() > 30 || saveParam.getAddress2().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "门牌号应在1~30个字之间");
        }

        if (ToolsUtils.containsEmoji(saveParam.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺名称不能包含表情");
        }
        if (ToolsUtils.containsEmoji(saveParam.getIntro())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：经营范围不能包含表情");
        }
        if (ToolsUtils.containsEmoji(saveParam.getTelephone())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：联系电话不能包含表情");
        }
        if (ToolsUtils.containsEmoji(saveParam.getContact())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：联系人不能包含表情");
        }
        if (ToolsUtils.containsEmoji(saveParam.getAddress2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：门牌号不能包含表情");
        }
        MyStaffShop entity = new MyStaffShop();
        BeanUtils.copyProperties(saveParam, entity);
        if (ObjectUtils.isEmpty(saveParam.getId())) {
            // 如果id为空，则新增附近店铺；
            MyStaffShopQueryParam queryParam = new MyStaffShopQueryParam();
            queryParam.setStaffId(currentStaff.getId());
            List<MyStaffShopDto> myShops = myStaffShopService.selectList(queryParam);
            if (!ObjectUtils.isEmpty(myShops) || myShops.size() > 0) {
                return WxMiniResponse.error(1010, "您已经创建了一个附近店铺,不能创建店铺了；");
            }
            entity.setCreateTime(new Date().getTime() / 1000);
            entity.setStaffId(currentStaff.getId());
            ToolsLocation toolsLocation = ToolsUtils.qq2baidu(entity.getLat(), entity.getLng());
            entity.setLatgd(toolsLocation.getLat());
            entity.setLnggd(toolsLocation.getLng());
            BaiduReverseGeocoding baiduReverseGeocoding = BaiduMapUtils.getBaiduAddressInfo(entity.getLng(), entity.getLat());
            if (!ObjectUtils.isEmpty(baiduReverseGeocoding)) {
                BaiduAddressComponent addressComponent = baiduReverseGeocoding.getResult().getAddressComponent();
                if (!ObjectUtils.isEmpty(addressComponent)) {
                    String region = addressComponent.getProvince() + "," + addressComponent.getCity() + "," + addressComponent.getDistrict();
                    entity.setRegion(region);
                    String code = addressComponent.getAdcode();
                    if (!ObjectUtils.isEmpty(code)) {
                        entity.setDistrictid(code);
                        entity.setDistrictid1(code.substring(0, 4));
                        entity.setDistrictid2(code.substring(0, 2));
                    }
                }
            }
            entity = myStaffShopService.addEntityAndSearch(entity);
            if (ObjectUtils.isEmpty(entity)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "创建店铺失败");
            }
        } else {
            // 如果id不为空，则更新附近店铺；
            // 更新之前判断该店铺是否是当前登陆人所属店铺；
            MyStaffShop shop = myStaffShopService.selectById(saveParam.getId());
            if (ObjectUtils.isEmpty(shop)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您的店铺不存在或已被删除");
            }
            if (!ObjectUtils.isEmpty(shop.getStaffId()) && shop.getStaffId().equals(currentStaff.getId())) {
                entity = myStaffShopService.updateEntityAndSearch(entity);
                if (ObjectUtils.isEmpty(entity)) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "更新失败");
                }
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "店铺信息异常，该店铺不是您的店铺！");
            }
        }
        MyStaffShopDto result = new MyStaffShopDto();
        BeanUtils.copyProperties(entity, result);
        return WxMiniResponse.ok(result);
    }

    /**
     * 附近店铺 退店附近店铺
     *
     * @param deleteParam 封装的删除实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delStaffShopInfo")
    public WxMiniResponse delStaffShopInfo(@RequestBody BaseDeleteParam deleteParam) {
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(deleteParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }

        MyStaffShop shop = myStaffShopService.selectById(deleteParam.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "该店铺不存在或已被删除，请误重复操作!");
        }
        Boolean result = myStaffShopService.deleteByIdAndSearch(deleteParam.getId());
        if (result)
            return WxMiniResponse.ok();
        else
            return WxMiniResponse.error(2001, "删除失败");
    }


    /**
     * 附近店铺 获取附近店铺搜索历史记录
     *
     * @param queryParam 封装的查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getSearchKeywordList")
    public WxMiniResponse getSearchKeywordList(@RequestBody MyStaffSearchQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.ok();
        }
        queryParam.setStaffId(currentStaff.getId());
        WxMiniPageDto<MyStaffSearchDto> resultList = myStaffSearchService.selectPageList(queryParam);
        return WxMiniResponse.ok(resultList);

    }

    /**
     * 附近店铺 删除附近店铺单个搜索历史记录
     *
     * @param deleteParam 封装的删除实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delSearchKeyword")
    public WxMiniResponse delSearchKeyword(@RequestBody BaseDeleteParam deleteParam) {
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(deleteParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }
        Boolean result = myStaffSearchService.deleteById(deleteParam.getId());
        if (result) {
            return WxMiniResponse.ok("删除成功！");
        } else {
            return WxMiniResponse.error(1010, "删除失败");
        }
    }

    /**
     * 附近店铺 删除附近店铺所有搜索历史记录
     *
     * @param deleteParam 封装的删除实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delSearchKeywordAll")
    public WxMiniResponse delSearchKeywordAll(@RequestBody BaseDeleteParam deleteParam) {
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        Boolean result = myStaffSearchService.deleteByStaffAll(currentStaff.getId());
        if (result) {
            return WxMiniResponse.ok("删除成功！");
        } else {
            return WxMiniResponse.error(1010, "删除失败");
        }
    }

    /**
     * 验证当前登陆用户是否已经入驻厂家或工厂；
     *
     * @param param 封装的查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/ruzhu")
    public WxMiniResponse ruzhu(@RequestBody StaticParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }
        Boolean result = myShopService.isShopCreateed(param.getId());
        if (result) {
            return WxMiniResponse.ok(1);
        }
        return WxMiniResponse.ok(0);
    }

    /**
     * 个人店铺 --获取店铺信息
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getMemberInfo")
    public WxMiniResponse getMemberInfo(@RequestBody StaticParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getStaffId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数[id]为空");
        }
        MyStaff staff = super.myStaffService.selectMyStaffById(param.getStaffId());
        if (ObjectUtils.isEmpty(staff)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "用户不存在");
        }
        MyStaffDto dto = new MyStaffDto();
        BeanUtils.copyProperties(staff, dto);
        return WxMiniResponse.ok(dto);
    }

    /**
     * 个人店铺 --  新增或编辑
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setStaffAddress")
    public WxMiniResponse setStaffAddress(@RequestBody MyStaffSaveParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺名称不能为空！");
        }
        if (ObjectUtils.isEmpty(param.getLogo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请上店铺照片！");
        }
        if (ObjectUtils.isEmpty(param.getMobile())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请填写您的手机号码！");
        }
        if (ObjectUtils.isEmpty(param.getLat()) || ObjectUtils.isEmpty(param.getLng())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择店铺地理位置！");
        }
        if (ObjectUtils.isEmpty(param.getAddress2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入门牌号！");
        }
        if (ObjectUtils.isEmpty(param.getCategoryUtype())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择行业分类");
        }

        if (param.getTitle().length() > 20 || param.getTitle().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "店铺名称应在1~20个字之间");
        }
        if (param.getAddress2().length() > 30 || param.getAddress2().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "门牌号应在1~30个字之间");
        }

        if (ToolsUtils.containsEmoji(param.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：店铺名称不能包含表情");
        }
        if (ToolsUtils.containsEmoji(param.getMobile())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：联系电话不能包含表情");
        }
        if (ToolsUtils.containsEmoji(param.getAddress2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：门牌号不能包含表情");
        }
        MyStaff entity = new MyStaff();
        BeanUtils.copyProperties(param, entity);
        entity.setId(currentStaff.getId());
        if (!ObjectUtils.isEmpty(entity.getLat()) && !ObjectUtils.isEmpty(entity.getLng())) {
            ToolsLocation toolsLocation = ToolsUtils.qq2baidu(entity.getLat(), entity.getLng());
            entity.setLatgd(toolsLocation.getLat());
            entity.setLnggd(toolsLocation.getLng());
            BaiduReverseGeocoding baiduReverseGeocoding = BaiduMapUtils.getBaiduAddressInfo(entity.getLng(), entity.getLat());
            if (!ObjectUtils.isEmpty(baiduReverseGeocoding)) {
                BaiduAddressComponent addressComponent = baiduReverseGeocoding.getResult().getAddressComponent();
                if (!ObjectUtils.isEmpty(addressComponent)) {
                    String region = addressComponent.getProvince() + "," + addressComponent.getCity() + "," + addressComponent.getDistrict();
                    entity.setRegion(region);
                    String code = addressComponent.getAdcode();
                    if (!ObjectUtils.isEmpty(code)) {
                        entity.setDistrictid(code);
                        entity.setDistrictid1(code.substring(0, 4));
                        entity.setDistrictid2(code.substring(0, 2));
                    }
                }
            }
        }
        entity.setStype(1);
        if (ObjectUtils.isEmpty(param.getCategoryUtype()))
            entity.setCategoryUtype(10);
        entity = super.myStaffService.updateEntityToShop(entity);
        String key = RedisKeyEnum.REDIS_KEY_GUID + currentStaff.getGuid();
        redisCache.deleteObject(key);
        if (ObjectUtils.isEmpty(entity)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
        return WxMiniResponse.ok(entity);
    }

    /**
     * 获取当前登陆用户基本信息
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/index")
    public WxMiniResponse index(@RequestBody StaticParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
            Map<String, Object> map = new HashMap<>();
            map.put("shopurl", myStaffConfig.getShopUrl());
            map.put("factoryurl", myStaffConfig.getFactoryUrl());
            map.put("shop", null);
            map.put("factory", null);
            map.put("telephone", "");
            map.put("member", null);
            map.put("setting", null);
            return WxMiniResponse.ok(map);
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        MyStaffDto member = new MyStaffDto();
        BeanUtils.copyProperties(currentStaff, member);
        MyLabel mylabel = myLabelService.selectByName("kefutel");
        MyConfig myConfig = myConfigService.selectByName("isvideoplay");
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        MyShopDto shopDto = new MyShopDto();
        if (!ObjectUtils.isEmpty(shop)) {
            BeanUtils.copyProperties(shop, shopDto);
            if (!ObjectUtils.isEmpty(shop.getPid())) {
                List<String> pidStr = Arrays.asList(ToolsUtils.trimLeftAndRight(shop.getPid(), "").split(","));
                shopDto.setPid(pidStr);
                List<MyCategoryShop> categoryShops = myCategoryShopService.selectList(null, pidStr, null, null);
                List<String> pidNames = new ArrayList<>();
                for (MyCategoryShop item : categoryShops) {
                    pidNames.add(item.getName());
                }
                shopDto.setPidnames(String.join(",", pidNames));
            } else {
                shopDto.setPidnames(null);
                shopDto.setPid(null);
            }
            // 这里有两种方式实现解码；
//            HtmlUtils.htmlUnescape(shop.getBaojiaremark());
            shopDto.setBaojiaremark(StringEscapeUtils.unescapeHtml4(shop.getBaojiaremark()));
            shopDto.setXiaoshouremark(StringEscapeUtils.unescapeHtml4(shop.getXiaoshouremark()));
            shopDto.setLoginurl(myStaffConfig.getShopUrl());
            shopDto.setTelephone(Arrays.asList(shop.getTelephone().split(",")));
            shopDto.setContent(StringEscapeUtils.unescapeHtml4(shop.getContent()));
            shopDto.setShebei(StringEscapeUtils.unescapeHtml4(shop.getShebei()));
            if (!ObjectUtils.isEmpty(shop.getImages())) {
                shopDto.setImages(Arrays.asList(shop.getImages()));
            } else {
                shopDto.setImages(null);
            }
            MyPunishment punishment = null;
            //这里开始查询该工厂的会员信息；

//            if (!ObjectUtils.isEmpty(shop.getPageDto<T>())) {
//                Long nowTime = new Date().getTime() / 1000;
//                if (shop.getViptime() + 604800 < nowTime) {
//                    if (!ObjectUtils.isEmpty(shop.getStatus()) && !shop.getStatus().equals(0)) {
//                        myShopService.updateShopStatus(shop.getId(), 0);
//                        myFactoryFavService.deleteByShopId(shop.getId());
//                        shopDto.setStatus(0);
//                        List<MyPunishment> punishments = myPunishmentService.selectList(shop.getStaffid(), 1, shop.getId());
//                        if (ObjectUtils.isEmpty(punishments)) {
//                            punishment = myPunishmentService.addEntity(new MyPunishment().setStaffid(shop.getStaffid()).setType(1).setUserid(shop.getId()).setCreateTime(new Date().getTime() / 1000).setStatus(1));
//                        }
//                    }
//                }
//            }
            if (!ObjectUtils.isEmpty(shopDto.getStatus()) && shopDto.getStatus().equals(0)) {
                if (ObjectUtils.isEmpty(punishment)) {
                    List<MyPunishment> punishments = myPunishmentService.selectList(shop.getStaffid(), 1, shop.getId());
                    if(punishments.size()>0){
                        punishment = punishments.get(0);
                    }
                }
                shopDto.setPunishment(punishment);
            }
            MyShopMemberQueryParam shopMemberQueryParam = new MyShopMemberQueryParam();
            shopMemberQueryParam.setShopid(shop.getId());
            shopMemberQueryParam.setStatus(0);
            Long auditnum = myShopMemberService.selectCount(shopMemberQueryParam);
            shopDto.setAuditnum(auditnum);
            shopDto.setContent(StringEscapeUtils.unescapeHtml4(shop.getContent()));
        } else {
            shopDto = null;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("shopurl", myStaffConfig.getShopUrl());
        map.put("factoryurl", myStaffConfig.getFactoryUrl());
        map.put("shop", shopDto);
        map.put("factory", null);
        map.put("telephone", ObjectUtils.isEmpty(mylabel.getInfo()) ? "" : mylabel.getInfo());
        map.put("member", member);
        if (!ObjectUtils.isEmpty(myConfig)) {
            map.put("setting", myConfig.getValue());
        } else {
            map.put("setting", "false");
        }
        return WxMiniResponse.ok(map);
    }

    /**
     * 报价单 --  获取数据列表
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/order")
    public WxMiniResponse order(@RequestBody MyOrderQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        param.setStaffid(currentStaff.getId());
        if (ObjectUtils.isEmpty(param.getType())) {
            param.setType(1);
        }
        WxMiniPageDto<MyOrderDto> resultList = this.myOrderService.selectPageList(param);
        return WxMiniResponse.ok(resultList);
    }

    /**
     * 个人资料- 修改个人头像和名称
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/saveinfo")
    public WxMiniResponse saveinfo(@RequestBody MyStaffSaveParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }

        if (ObjectUtils.isEmpty(param.getHeadimgurl())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：个人头像不能为空！");
        }
        if (ObjectUtils.isEmpty(param.getUserreal())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：用户名称不能为空！");
        }
        currentStaff.setHeadimgurl(param.getHeadimgurl());
        currentStaff.setUserreal(param.getUserreal());
        currentStaff = this.myStaffService.updateEntity(currentStaff);
        String key = RedisKeyEnum.REDIS_KEY_GUID + currentStaff.getGuid();
        redisCache.deleteObject(key);
        return WxMiniResponse.ok(currentStaff);
    }

    /**
     * 工厂信息- 修改我的工厂信息；
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/saveinfo2")
    public WxMiniResponse saveinfo2(@RequestBody MyFactorySaveParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司名称");
        }
        if (ObjectUtils.isEmpty(param.getTitle1())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司简称");
        }
        if (param.getTitle1().length() > 4 || param.getTitle1().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "公司简称应在1~4个字之间");
        }
        if (ObjectUtils.isEmpty(param.getLogo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请上传logo");
        }
        if (ObjectUtils.isEmpty(param.getLat()) || ObjectUtils.isEmpty(param.getLng())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择地理位置");
        }
        if (ObjectUtils.isEmpty(param.getAddress())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司地址");
        }
        if (ObjectUtils.isEmpty(param.getContact())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入联系人姓名");
        }
        if (ObjectUtils.isEmpty(param.getPid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择生产类别");
        }
        if (ObjectUtils.isEmpty(param.getTelephone())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入手机号码");
        }
        if (param.getTitle().matches("[AaBbCc].*")) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：公司名称不能以ABC开头");
        }

        MyShop shop = this.myShopService.selectShopByStaffId(currentStaff.getId());
        param.setId(shop.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "校验失败：您的厂家异常");
        }
        BeanUtils.copyProperties(param, shop);

        if (!ObjectUtils.isEmpty(shop.getLat()) && !ObjectUtils.isEmpty(shop.getLng())) {
            ToolsLocation toolsLocation = ToolsUtils.qq2baidu(shop.getLat(), shop.getLng());
            shop.setLat(toolsLocation.getLat());
            shop.setLng(toolsLocation.getLng());

            shop.setLatgd(shop.getLat());
            shop.setLnggd(shop.getLng());
            BaiduReverseGeocoding baiduReverseGeocoding = BaiduMapUtils.getBaiduAddressInfo(shop.getLng(), shop.getLat());
            if (!ObjectUtils.isEmpty(baiduReverseGeocoding)) {
                BaiduAddressComponent addressComponent = baiduReverseGeocoding.getResult().getAddressComponent();
                if (!ObjectUtils.isEmpty(addressComponent)) {
                    String region = addressComponent.getProvince() + "," + addressComponent.getCity() + "," + addressComponent.getDistrict();
                    shop.setRegion(region);
                    shop.setPcd(region);
                    String code = addressComponent.getAdcode();
                    if (!ObjectUtils.isEmpty(code)) {
                        shop.setDistrictid(code);
                        shop.setDistrictid1(code.substring(0, 4));
                        shop.setDistrictid2(code.substring(0, 2));
                    }
                }
            }
        }
        shop.setEn(ToolsUtils.getFirstLetterUpper(shop.getTitle()));
        shop.setPid("," + shop.getPid() + ",");
        shop = myShopService.updateEntity(shop);
//        if(ObjectUtils.isEmpty(param.getId())){
//            myShopService.addEntity(shop);
//        }else{
//            myShopService.updateEntity(shop);
//        }
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "保存失败");
        }
        return WxMiniResponse.ok();
    }


    /**
     * 报价单- 清除我的所有报价单
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/clearorder")
    public WxMiniResponse clearorder(@RequestBody MyOrderQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getType())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择需要清除的类型（'销售单'或'报价单'）");
        }
        param.setStaffid(currentStaff.getId());
        List<MyOrder> selectList = myOrderService.selectList(param);
        if (!ObjectUtils.isEmpty(selectList)) {
            // 这里添加条件判断是否删除报价单详情；
            List<String> ordernos = new ArrayList<>();
            for (MyOrder myOrder : selectList) {
                ordernos.add(myOrder.getOrderno());
            }
            // 开始使用in 条件，删除报价单详情！
            myOrderDetailService.deleteByOrderNoAndStaffId(currentStaff.getId(), ordernos);
        }
        Boolean result = myOrderService.deleteStaffAndType(currentStaff.getId(), param.getType());
        if (result) {
            return WxMiniResponse.ok("操作成功");
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
    }

    /**
     * 报价单- 清除我的单个报价单
     *
     * @param param 封装的通用查询实体类
     * @return 标准响应体封装返回；
     * @ApiNote
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delorder")
    public WxMiniResponse delorder(@RequestBody MyOrderQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择需要删除的数据！");
        }
        param.setStaffid(currentStaff.getId());
        List<MyOrder> selectList = myOrderService.selectList(param);
        if (!ObjectUtils.isEmpty(selectList)) {
            // 这里添加条件判断是否删除报价单详情；
            List<String> ordernos = new ArrayList<>();
            for (MyOrder myOrder : selectList) {
                ordernos.add(myOrder.getOrderno());
            }
            // 开始使用in 条件，删除报价单详情！
            myOrderDetailService.deleteByOrderNoAndStaffId(currentStaff.getId(), ordernos);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "失败");
        }
        Boolean result = myOrderService.deleteStaffAndId(currentStaff.getId(), param.getId());
        if (result) {
            return WxMiniResponse.ok("操作成功");
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
    }


    /**
     * @api {GET} /Member/staffInfo 获取用户详细信息
     * @apiVersion 1.0.0
     * @apiName staffInfo
     * @apiGroup Member
     * @apiParam {string}  guid 用户标识
     * @apiParam {int}  staffId 其他用户id
     */
    @PostMapping("/staffInfo")
    public WxMiniResponse staffInfo(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        MyStaff staffinfo = new MyStaff();
        if (ObjectUtils.isEmpty(param.getStaffId()) || param.getStaffId().equals(0)) {
            if (!this.isCheckLogin(param.getGuid())) {
                //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//                return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
                Map<String, Object> map = new HashMap<>();
                map.put("hg", 0);
                map.put("isfav", 0);
                map.put("audtoNo", 0);
                map.put("collectionNo", 0);
                map.put("thumbupNo", 0);
                map.put("favNo", 0);
                map.put("bfavNo", 0);
                map.put("shopId", 0);
                map.put("factoryId", 0);
                map.put("goodsShop", 0);
                return WxMiniResponse.ok(map);
            } else {
                BeanUtils.copyProperties(currentStaff, staffinfo);
            }
        } else {
            staffinfo = this.myStaffService.selectMyStaffById(param.getStaffId());
        }
        MyStaff userInfo = staffinfo;
        Long userfav = 0L;
        Long isFav = 0L;
        Long audtoNo = 0L;
        Long collectionNo = 0L;
        Long thumbupNo = 0L;
        Long favNo = 0L;
        Long bfavNo = 0L;
        Long shopId = 0L;
        Long factoryId = 0L;
        Long goodsShop = 0L;
        if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
            // 查询该用户我是否已关注
            MyFactoryFavQueryParam favQueryParam = new MyFactoryFavQueryParam();
            favQueryParam.setFavStaffid(param.getStaffId());
            favQueryParam.setStaffId(currentStaff.getId());
            favQueryParam.setType(0);
            isFav = this.myFactoryFavService.selectCount(favQueryParam);
            if (!isFav.equals(0L)) {
                // 如果已关注了该用户，查询该用户是否已关注我，互关的判断；
                favQueryParam.setFavStaffid(currentStaff.getId());
                favQueryParam.setStaffId(param.getStaffId());
                userfav = this.myFactoryFavService.selectCount(favQueryParam);
            }

            // 查询我的推荐信息数
            MyCircleQueryParam circleQueryParam = new MyCircleQueryParam();
            circleQueryParam.setStaffId(userInfo.getId());
            circleQueryParam.setUtype(1);
            audtoNo = myCircleService.selectCount(circleQueryParam);
            // 查询收藏数
            MyCircleCollectionQueryParam circleCollectionQueryParam = new MyCircleCollectionQueryParam();
            circleCollectionQueryParam.setStaffId(userInfo.getId());
            collectionNo = myCircleCollectionService.selectCountToCricle(circleCollectionQueryParam);
            MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
            myFactoryFavQueryParam.setStaffId(userInfo.getId());
            myFactoryFavQueryParam.setType(0);
            favNo = myFactoryFavService.selectCount(myFactoryFavQueryParam);
        }
        // 查询点赞数
        thumbupNo = myCircleThumbupService.selectCountToCricle(userInfo.getId());
        //查询关注数

        // 查询被关注数（粉丝数）
        MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
        myFactoryFavQueryParam.setStaffId(null);
        myFactoryFavQueryParam.setFavStaffid(userInfo.getId());
        bfavNo = myFactoryFavService.selectCount(myFactoryFavQueryParam);

        // 查询用户工厂ID
        MyShopQueryParam shopQueryParam = new MyShopQueryParam();
        shopQueryParam.setStaffid(userInfo.getId());
        shopQueryParam.setStatus(1);
        shopQueryParam.setAudit(1);
        List<MyShop> myShops = myShopService.selectList(shopQueryParam);
        if (!ObjectUtils.isEmpty(myShops)) {
            shopId = Long.parseLong(myShops.get(0).getId() + "");
        }

        //查询用户市场ID，这里功能作废，市场相关功能暂时关闭；后续会考虑添加；

        //查询用户附近店铺信息
        MyStaffShopQueryParam staffShopQueryParam = new MyStaffShopQueryParam();
        staffShopQueryParam.setStaffId(userInfo.getId());
        List<MyStaffShopDto> staffShopDtos = myStaffShopService.selectList(staffShopQueryParam);
        if (!ObjectUtils.isEmpty(staffShopDtos)) {
            goodsShop = Long.parseLong(staffShopDtos.get(0).getId() + "");
        }
        Map<String, Object> map = new HashMap<>();
        try {
            map = ToolsUtils.toMap(userInfo);
            map.put("hg", userfav);
            map.put("isfav", isFav);
            map.put("audtoNo", audtoNo);
            map.put("collectionNo", collectionNo);
            map.put("thumbupNo", thumbupNo);
            map.put("favNo", favNo);
            map.put("bfavNo", bfavNo);
            map.put("shopId", shopId);
            map.put("factoryId", factoryId);
            map.put("goodsShop", goodsShop);

        } catch (IllegalAccessException e) {
            return WxMiniResponse.error(2001, "后台报错!" + e.getMessage());
        }
        return WxMiniResponse.ok(map);
    }

    /**
     * @api {GET} /Member/editorder 我的报价单-编辑报价单
     * @apiVersion 1.0.0
     * @apiName staffInfo
     * @apiGroup Member
     * @apiParam {string}  guid 用户标识
     * @apiParam {int}  staffId 其他用户id
     */
    @PostMapping("/editorder")
    public WxMiniResponse editorder(@RequestBody StaticParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空！");
        }

        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数报价单为空！");
        }

        MyOrder order = myOrderService.selectById(param.getId());
        List<MyCart> cartList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(order)) {
            List<MyOrderDetail> orderDetails = myOrderDetailService.selectByOrderNo(order.getOrderno());
            for (MyOrderDetail item : orderDetails) {
                MyFactoryProduct product = myFactoryProductService.selectById(item.getProductid());
                if (!ObjectUtils.isEmpty(product)) {
                    MyCart cart = new MyCart();
                    BeanUtils.copyProperties(item, cart);
                    cart.setStaffid(currentStaff.getId());
                    cart.setUtype(1);
                    cart.setPrice(product.getPrice());
                    cart.setPriceQ(product.getPriceQ());
                    cart.setPriceZ(product.getPriceZ());
//                    cart.setRealprice(product.getRealprice());//暂无此字段
//                    cart.setRealpriceQ(product.getRealpriceQ());//暂无此字段
//                    cart.setRealpriceZ(product.getRealpriceZ());//暂无此字段
                    cart.setIstax(order.getIstax());
                    cart.setIszhou(order.getIszhou());
                    cart.setBiaozhun(order.getBiaozhun());
                    cart.setSourceType(order.getSourceType());
                    cart.setSource(1);
                    if (!ObjectUtils.isEmpty(order.getFactoryid()) || !ObjectUtils.isEmpty(order.getShopid())) {
                        cart.setSource(2);
                    }
                    cartList.add(cart);
                }
            }
            System.out.println(cartList);
            Boolean result = myCartService.addEntitys(cartList);
            if (result)
                return WxMiniResponse.ok();
            else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
            }
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
    }

    /**
     * @api {GET} /Member/myfav 获取我的关注用户列表；
     * @apiVersion 1.0.0
     */
    @PostMapping("/myfav")
    public WxMiniResponse myfav(@RequestBody MyFactoryFavQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        param.setStaffId(currentStaff.getId());
        WxMiniPageDto<MyFactoryFavDto> result = this.myFactoryFavService.selectPageList(param);
        return WxMiniResponse.ok(result);
    }


    /**
     * @api {GET} /Member/favStaff 用户关注用户（视频）
     * @apiVersion 1.0.0
     */
    @PostMapping("/favStaff")
    public WxMiniResponse favStaff(@RequestBody MyFactoryFavQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getStaffId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：关注用户标识为空");
        }
        MyStaff staff = this.myStaffService.selectMyStaffById(param.getStaffId());
        if (ObjectUtils.isEmpty(staff)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：关注用户不存在");
        }
        MyFactoryFavQueryParam favQueryParam = new MyFactoryFavQueryParam();
        favQueryParam.setStaffId(currentStaff.getId());
        favQueryParam.setFavStaffid(param.getStaffId());
        favQueryParam.setType(0);
        Long count = this.myFactoryFavService.selectCount(favQueryParam);
        String str = "关注";
        Boolean result = false;
        if (!ObjectUtils.isEmpty(count) && count > 0) {
            str = "取消关注";
            result = myFactoryFavService.deleteByStaffId(currentStaff.getId(), param.getStaffId());
        } else {
            MyFactoryFav fav = new MyFactoryFav();
            fav.setStaffid(currentStaff.getId());
            fav.setFavStaffid(param.getStaffId());
            fav.setType(0);
            fav = myFactoryFavService.addEntity(fav);
            if (!ObjectUtils.isEmpty(fav)) {
                result = true;
            }
        }
        if (!result) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), str + "失败");
        }
        return WxMiniResponse.ok(str + "成功");
    }

    /**
     * @api {GET} /Member/favOfStaff 用户关注用户（首页推荐）
     * @apiVersion 1.0.0
     */
    @PostMapping("/favOfStaff")
    public WxMiniResponse favOfStaff(@RequestBody MyFactoryFavQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getStaffId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：关注用户标识为空");
        }
        MyStaff staff = this.myStaffService.selectMyStaffById(param.getStaffId());
        if (ObjectUtils.isEmpty(staff)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：关注用户不存在");
        }
        MyFactoryFavQueryParam favQueryParam = new MyFactoryFavQueryParam();
        favQueryParam.setStaffId(currentStaff.getId());
        favQueryParam.setFavStaffid(param.getStaffId());
        favQueryParam.setType(0);
        Long count = this.myFactoryFavService.selectCount(favQueryParam);
        String str = "关注";
        Boolean result = false;
        if (!ObjectUtils.isEmpty(count) && count > 0) {
            str = "取消关注";
            result = myFactoryFavService.deleteByStaffId(currentStaff.getId(), param.getStaffId());
        } else {
            MyFactoryFav fav = new MyFactoryFav();
            fav.setStaffid(currentStaff.getId());
            fav.setFavStaffid(param.getStaffId());
            fav.setType(0);
            fav = myFactoryFavService.addEntity(fav);
            if (!ObjectUtils.isEmpty(fav)) {
                result = true;
            }
        }
        if (!result) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), str + "失败");
        }
        return WxMiniResponse.ok(str + "成功");
    }

    /**
     * @api {GET} /Member/myquitfav 取消关注
     * @apiVersion 1.0.0
     */
    @PostMapping("/myquitfav")
    public WxMiniResponse myquitfav(@RequestBody MyFactoryFavQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数标识为空");
        }
        String str = "取消关注";
        Boolean result = myFactoryFavService.deleteById(param.getId());
        if (!result) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), str + "失败");
        }
        return WxMiniResponse.ok(str + "成功");
    }

    /**
     * @api {GET} /Member/delStaffBusinessInfo 个人店铺-删除
     * @apiVersion 1.0.0
     */
    @PostMapping("/delStaffBusinessInfo")
    public WxMiniResponse delStaffBusinessInfo(@RequestBody BaseSaveParams param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        Boolean result = this.myStaffService.deleteMyStore(currentStaff);
        if (result) {
            String key = RedisKeyEnum.REDIS_KEY_GUID + currentStaff.getGuid();
            redisCache.deleteObject(key);
            return WxMiniResponse.ok();
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败");
        }
    }

    /**
     * @api {GET} /Member/delStaffBusinessInfo 个人店铺-删除
     * @apiVersion 1.0.0
     */
    @PostMapping("/setStaffCategoryNoShop")
    public WxMiniResponse setStaffCategoryNoShop(@RequestBody MyCategoryStaffSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：数据为空!");
        }
        if (ObjectUtils.isEmpty(saveParam.getShopId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空【shopId】");
        }
        if (ObjectUtils.isEmpty(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空【name】");
        }
        if (ToolsUtils.containsEmoji(saveParam.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：商品分类名称不能包含表情");
        }
        if (saveParam.getName().length() > 6 || saveParam.getName().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "商品分类名称应在1~6个字之间");
        }

        if (ObjectUtils.isEmpty(saveParam.getId())) {
            // 如果id不存在，则新增；
            if (ObjectUtils.isEmpty(saveParam.getSort())) {
                saveParam.setSort(0);
            }
            MyCategoryStaff entity = new MyCategoryStaff();
            BeanUtils.copyProperties(saveParam, entity);
            entity.setStaffId(currentStaff.getId());
            entity.setPid(0);
            entity.setStatus(2);
            entity.setCreateTime(new Date().getTime() / 1000);
            entity.setCreateUser(currentStaff.getId() + "");
            entity = this.myCategoryStaffService.addEntity(entity);
            return WxMiniResponse.ok("添加成功");
        } else {
            // 如果id存在，则更新；
            if (ObjectUtils.isEmpty(saveParam.getSort())) {
                saveParam.setSort(0);
            }
            MyCategoryStaff entity = new MyCategoryStaff();
            BeanUtils.copyProperties(saveParam, entity);
            entity.setStaffId(currentStaff.getId());
            entity.setUpdateTime(new Date().getTime() / 1000);
            entity.setUpdateUser(currentStaff.getId() + "");
            entity = this.myCategoryStaffService.updateEntity(entity);
            return WxMiniResponse.ok("更新成功");
        }
    }

    /**
     * @api {GET} /Member/setStaffCategorySort 商品分类排序
     * @apiVersion 1.0.0
     */
    @PostMapping("/setStaffCategorySort")
    public WxMiniResponse setStaffCategorySort(@RequestBody CategoryStaffListSaveParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：更新参数为空");
        }
        if (ObjectUtils.isEmpty(param.getList())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：更新参数为空");
        }
        List<MyCategoryStaffSaveParam> list = new ArrayList<>();
        list = JSONArray.parseArray(param.getList(), MyCategoryStaffSaveParam.class);
        List<MyCategoryStaff> convertList = list.stream().map(po -> {
            MyCategoryStaff entity = new MyCategoryStaff();
            BeanUtils.copyProperties(po, entity);
            entity.setUpdateTime(new Date().getTime() / 1000);
            entity.setUpdateUser(currentStaff.getId() + "");
            return entity;
        }).collect(Collectors.toList());
        Boolean result = this.myCategoryStaffService.updateEntitys(convertList);
        if (result) {
            return WxMiniResponse.ok();
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
    }

    /**
     * verifyStaffShop 验证用户商铺是否已开
     *
     * @api verifyStaffShop 验证用户商铺是否已开
     * @apiVersion 1.0.0
     */
    @PostMapping("/verifyStaffShop")
    public WxMiniResponse verifyStaffShop(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (!ObjectUtils.isEmpty(param.getType()) && param.getType().equals(0)) {
            MyStaffShopQueryParam queryParam = new MyStaffShopQueryParam();
            queryParam.setStaffId(currentStaff.getId());
            MyStaffShop shop = this.myStaffShopService.selectOne(queryParam);
            if (!ObjectUtils.isEmpty(shop)) {
                MyStaffShopDto dto = new MyStaffShopDto();
                BeanUtils.copyProperties(shop, dto);
                return WxMiniResponse.ok(dto);
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "校验失败，店铺不存在", "校验失败，店铺不存在！");
            }
        } else {
            if (!ObjectUtils.isEmpty(currentStaff) && currentStaff.getStype().equals(1)) {
                return WxMiniResponse.ok(currentStaff);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "校验失败，店铺不存在", "校验失败，店铺不存在！");
    }


    /**
     * @api {Post} /Member/getStaffShopGoodsTuiList 获取附近店家商品列表
     * @apiParam {string}  guid 用户标识
     * @apiParam {int}  staffId    用户id
     * @apiParam {int}  shopId 店铺id
     * @apiParam {string}  type 0 附近店铺 1 商家店铺
     * @apiParam {int}  id 商品id
     */
    @PostMapping("/getStaffShopGoodsTuiList")
    public WxMiniResponse getStaffShopGoodsTuiList(@RequestBody StaticParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；

        }
        List<MyStaffShopGoods> list = myStaffShopGoodsService.getStaffShopGoodsTuiList(param);
        if (list.size() > 0) {
            List<MyStaffShopGoodsDto> dtoList = list.stream().map(po -> {
                MyStaffShopGoodsDto myStaffShopGoodsDto = new MyStaffShopGoodsDto();
                BeanUtils.copyProperties(po, myStaffShopGoodsDto);
                return myStaffShopGoodsDto;
            }).collect(Collectors.toList());
            Map map = new HashMap();
            map.put("data", dtoList);
            return WxMiniResponse.ok(map);
        }
        return WxMiniResponse.ok();
    }

    /**
     * @api {post} 商家介绍（帖子信息）信息校验接口
     * @apiParam {int} id 线缆圈id
     */
    @PostMapping("/verifyStaffShopGoodsId")
    public WxMiniResponse verifyStaffShopGoodsId(@RequestBody StaticParam param) {
//        if (!this.isCheckLogin(staticParam.getGuid())) {
//            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
//        }
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "传入参数为空", "传入参数为空");
        }
        if (ObjectUtils.isEmpty(param.getStaffId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "传入参数商铺标识为空", "传入参数商铺标识为空");
        }

        if (!ObjectUtils.isEmpty(param.getStaffId())) {
            MyStaff staff = this.myStaffService.selectMyStaffById(param.getStaffId());
            if (!ObjectUtils.isEmpty(staff)) {
                if (staff.getStype().equals(0)) {
                    return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商家不存在或已退店", "商家不存在或已退店");
                }
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商家不存在或已退店", "商家不存在或已退店");
            }
        }

        if (!ObjectUtils.isEmpty(param.getGoodsId()) && param.getGoodsId() > 0) {
            MyStaffShopGoods goods = myStaffShopGoodsService.selectById(param.getGoodsId());
            if (!ObjectUtils.isEmpty(goods)) {
                if (goods.getStatus().equals(0)) {
                    return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商品不存在或已删除", "商品不存在或已删除");
                }
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "商品不存在或已删除", "商品不存在或已删除");
            }
        }
        return WxMiniResponse.ok();
    }

}
